package com.example.rabbitextensionsdemo.config;

import com.example.rabbitextensionsdemo.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class DelayedConfig {
    // 延时队列插件
    @Bean("delayedQueue")
    public Queue delayedQueue() {
        return QueueBuilder.durable(Constants.DELAYED_QUEUE).build();
    }
    @Bean("delayedExchange")
    public Exchange delayedExchange() {
        // delayed声明插件
        return ExchangeBuilder.directExchange(Constants.DELAYED_EXCHANGE).delayed().build();
    }
    @Bean("delayedBinding")
    public Binding delayedBinding(@Qualifier("delayedQueue") Queue queue , @Qualifier("delayedExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("delayed").noargs();
    }
}
